package com.shengjing.apk;

import java.util.ArrayList;
import java.util.List;

import android.webkit.WebView;

public class History
{
    private List<String> mHistory = new ArrayList<String>();
    private WebView mWebView;
    
    public History(WebView webView) {
        mWebView = webView;
    }
    
    public void goBack() {
        mHistory.remove(mHistory.size() - 1);
        loadUrlWithAddToHistory(getCurrentUrl());
    }
    
    public int size() {
        return mHistory.size();
    }
    
    public void loadUrl(String url) {
        mWebView.loadUrl(url);
        addToHistory(url);
    }
    
    public void reloadUrl() {
        loadUrlWithAddToHistory(getCurrentUrl());
    }
    
    public void loadUrlWithAddToHistory(String url) {
        mWebView.loadUrl(url);
    }
    
    public void addToHistory(String url) {
        mHistory.add(url);
    }
    
    public String getCurrentUrl() {
        return mHistory.get(mHistory.size() - 1);
    }
    
}
